package unit11;

import java.io.*;
import java.net.*;
public class Ex11_2_EchoServer {
    public static void main(String[] args) {
        try {
            ServerSocket server = new ServerSocket(8080);
            Socket s = server.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    s.getInputStream()));
            PrintWriter out = new PrintWriter(s.getOutputStream(), true);
            out.println("Hello! Enter Bye to exit.");
            String line = "";
            while ((line = in.readLine()) != null) {
                out.println("Echo:" + line);
                if (line.trim().equalsIgnoreCase("BYE"))
                    break;
            }
            in.close();
            out.close();
            s.close();
            server.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
